#include "MTVariableDeclaration.hpp"
#include "MTInteger.hpp"
#include "MTDouble.hpp"
#include "MTFloat.hpp"
#include "MTExpression.hpp"
#include "Params.h"
#include <string>
#include <iostream>
#include <sstream>

namespace MathematicaTranslator
{
	std::string* MTVariableDeclaration::generateCode(CodeGenContext& context)
	{
		std::ostringstream ss;
		
		if( context.locals().find(id.name) != context.locals().end()) 
		{
			 //variable exist - error. Cannot redeclare !
			std::cerr << "variable: " << id.name << " redeclaration" <<std::endl;		
			return new std::string("VARIABLE REDECLARED - ERROR");
		} else 
		{
			ss << *id.generateCode(context);

		}
		std::string* generatedValue = new std::string(ss.str()); 

		//place new/modified value back to locals()
		context.locals()[id.name] = generatedValue;

		#ifdef DEBUG
			std::cout<<"Variable declaration created" <<std::endl;
		#endif

		return generatedValue;
	}

}
